package HanShuFangFa;

import java.util.Arrays;
import java.util.Scanner;

public class exercise02 {
    public static void showMenu02(){
        System.out.println("--------------------欢迎进入RBAC系统--------------------");
        System.out.println("按1.查询所有的武将");
        System.out.println("按2.根据类型查询对应的人物");
        System.out.println("按3.根据年龄查询对应的任务");
        System.out.println("按4.退出");
        System.out.print("请输入您的选项：");
    }

    public static void findAllHero(String[] arrs02){
        System.out.println(Arrays.toString(arrs02));
    }

    public static void findByType(Scanner scanner02, String[] arrs02){
        System.out.println("请输入类型:");
        String type02= scanner02.next();
        for (String name02 : arrs02){   //name02="黄忠-武将-55"
            String[] arr_type=name02.split("-");    //arr_type=["黄忠","武将","55"]
            if (type02.equals(arr_type[1])){
                System.out.println("search result :"+name02);
            }
        }
    }

    public static void findByAge(Scanner scanner02, String[] arrs02){
        System.out.println("input age:  ");
        int age02= scanner02.nextInt();
        for (String name02 : arrs02){   //name02="黄忠-武将-55"
            String[] arrs02_age = name02.split("-");    //arrs02_age=["黄忠","武将","55"]
            if (age02==Integer.parseInt(arrs02_age[2])){
                System.out.println("search result :"+name02);
            }
        }
    }

    public static void main(String[] args) {

        String[] arrs02 = {"黄忠-武将-55","貂蝉-美女-20","赵云-武将-30","张武将-美女-20","许褚-武将-35","吕布-武将-33"};
        showMenu02();

        Scanner scanner02 = new Scanner(System.in);
        int num02 = scanner02.nextInt();

        while (true){
            switch (num02){
                case 1:
                    findAllHero(arrs02);
                    break;
                case 2:
                    findByType(scanner02, arrs02);
                    break;
                case 3:
                    findByAge(scanner02, arrs02);
                    break;
                case 4:
                    System.exit(0);
            }
        }
        }
    }

